const mysql = require('mysql');
let articledata = {
    host: '127.0.0.1',
    port: 3306,
    user: 'root',
    password: 'root',
    database:'article' 
}
var connection = mysql.createConnection(articledata);
//连接数据库
connection.connect(function(err){
    if (err) {
        console.error('连接失败');
        return;
    }
    console.log('连接mysql成功');
});
module.exports=function(sql,bind=null,callback){
    // connection.query(sql,bind,callback)
    return new Promise(( resolve,reject )=>{
        connection.query(sql,bind,(err,result)=>{
            if(err){
                reject(err)
            }else{
                resolve(result)
            }
        })
    })
   

}